<script setup>
import { onMounted, ref } from 'vue'
import dial from '@/views/warehouse/warehouseArea/dial.vue'
import { getAllApi } from '@/api/warehouse/warehouseArea'
const tableData = ref('')
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(5)
const size = ref('default')
const background = ref(true)
const disabled = ref(false)
const handleSizeChange = (val) => {
  pageSize.value = val
  getAll()
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  getAll()
}
const form = ref({
  name: null,
  city: null,
})
const getAll = async () => {
  let res = await getAllApi(form.value.name, form.value.city, currentPage.value, pageSize.value)
  total.value = res.total
  tableData.value = res.rows
}
const diaRef = ref('diaRef')
const handleAdd = () => {
  diaRef.value.dialogVisible = true
}
defineExpose({
  refreshData: getAll,
  childMethods: {
    getWarehouse: () => diaRef.value?.getWarehouseList?.()
  }
})
// onMounted(() => {
//   getAll
// })
</script>
<template>
  <dial ref="diaRef" />
  <el-form :model="form" :inline="true" style="width: 1800px;">
    <el-form-item>
      <el-button @click="handleAdd" circle shadow="always">+</el-button>
    </el-form-item>
    <el-form-item>
      <el-input v-model="form.name" placeholder="仓库名称" />
    </el-form-item>
    <el-form-item>
      <el-input v-model="form.city" placeholder="所在城市" />
    </el-form-item>
  </el-form>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column type="selection" width="55" />
    <el-table-column property="warehouseName" label="仓库名称" width="120" />
    <el-table-column property="name" label="库区名称" width="120" />
    <el-table-column property="category" label="库区类型" width="120" />
    <el-table-column property="isDel" label="是否有效" width="240" />
    <el-table-column property="createTime" label="创建时间" width="240" />
    <el-table-column property="updateTime" label="修改时间" width="240" />
    <el-table-column fixed="right" label="操作" min-width="200">
      <template #default>
        <el-button type="primary" @click="handleClick">
          编辑
        </el-button>
        <el-button type="danger">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="demo-pagination-block">
    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 30, 40]"
      :size="size" :disabled="disabled" :background="background" layout="total, sizes, prev, pager, next, jumper"
      :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>